﻿using JHECIS.DataModel.DictModel;
using JHECIS.Interface;
using Microsoft.Practices.ServiceLocation;
using MS.Common.Helpers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading;

namespace JHECIS.BLL.Triage.Common
{
    public static class StaticHelper
    {
        /// <summary>
        /// 通过身份证号获取出生日期
        /// </summary>
        /// <returns></returns>
        public static DateTime GetTimeByIDCard(string ID)
        {
            try
            {
                var birth = ID.Substring(6, 8);
                return new DateTime(Convert.ToInt32(birth.Substring(0, 4)), Convert.ToInt32(birth.Substring(4, 2)), Convert.ToInt32(birth.Substring(6, 2)));
            }
            catch (Exception e)
            {
                LogHelper.GetLogHelper().Error("根据身份证生成出生日期报错！" + e);
                return DateTime.MinValue;
            }
        }
        /// <summary>
        /// 通过身份证号获取性别
        /// </summary>
        /// <returns></returns>
        public static string GetSexByIDCard(string ID)
        {
            try
            {
                if (int.Parse(ID.Substring(14, 3)) % 2 == 0) //性别代码为偶数是女性奇数为男性
                {
                    return "女";
                }
                else
                {
                    return "男";
                }
            }
            catch (Exception ex)
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// 基于当前时间处理 2022-04-08 袁凤超
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static DateTime TimeNowFor(NowType type)
        {
            DateTime now = DateTime.Now;
            switch (type)
            {
                case NowType.Now00:
                    return new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0);
                case NowType.Today00:
                    return new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
                case NowType.NowStart:
                    now = now.AddDays(-1);
                    return new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
                case NowType.NowEnd:
                    return new DateTime(now.Year, now.Month, now.Day, 23, 59, 59);
            }
            return now;
        }
    }


}
